<?php
/***************
* @Project	Warabi
* @Author	Feifei
* @Date		04/08/2009
***************/

/** this module is to generate 
	*an unique passcode for dpf and app
**/

class Guid{
	
	var $codeBeforeMD5;
	var $codeAfterMD5;

	function Guid(){
		$this->codeBeforeMD5 = $this->netAddress() .":". $this->currentTimeMillis() .":". $this->nextLong();
		$this->codeAfterMD5 = MD5($this->codeBeforeMD5);
	}

	function currentTimeMillis(){
		list($usec , $sec) = explode(" ",microtime());
		return $sec.substr($usec,2,3);
	}
	
	function nextLong()
    {
        $tmp = rand(0, 1) ? '-' : '';
        return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100,
            999).rand(100, 999);
    }

	function netAddress(){
		$addressName = isset($_ENV["COMPUTERNAME"]) ? $_ENV["COMPUTERNAME"] : "localhost";
        $addressIP = $_SERVER["SERVER_ADDR"];
		return strtolower($addressName."/".$addressIP);
	}

	function rawOutput(){
		return $this->codeAfterMD5;
	}
}


?>